<?php

declare(strict_types=1);

namespace App\WorkDepartment\Controller\Dashboard;

use App\WorkDepartment\QueueService\DepartmentApply;
use App\WorkEmployee\QueueService\EmployeeApply;
use Hyperf\Di\Annotation\Inject;
use Hyperf\HttpServer\Annotation\Controller;
use Hyperf\HttpServer\Annotation\Middleware;
use Hyperf\HttpServer\Annotation\Middlewares;
use Hyperf\HttpServer\Annotation\RequestMapping;
use App\Common\Middleware\DashboardAuthMiddleware;
use App\Corp\Service\CorpService;
use App\WorkDepartment\Logic\PageIndexLogic;
use App\WorkMessage\Service\WorkMessageConfigService;
use Base\Action\AbstractAction;
use Base\Constants\ErrorCode;
use Base\Exception\CommonException;
use Base\Request\ValidateSceneTrait;

/**
 * 组织架构-部门列表.
 *
 * Class PageIndex.
 * @Controller
 */
class PageIndex extends AbstractAction
{
    //use ValidateSceneTrait;

    /**
     * @Inject
     * @var CorpService
     */
    protected $corpService;

    /**
     * @Inject
     * @var WorkMessageConfigService
     */
    protected $workMessageConfigService;

    /**
     * @Inject
     * @var PageIndexLogic
     */
    private $pageIndexLogic;

    /**
     * @Middlewares({
     *     @Middleware(DashboardAuthMiddleware::class)
     * })
     * @RequestMapping(path="/dashboard/workDepartment/pageIndex", methods="get")
     * @return array 返回数组
     */
    public function handle(): array
    {
        $corp_id = $this->request->input('userInfo.corp_id');
        ## 判断用户绑定企业信息
        if (! isset($corp_id)) {
            throw new CommonException(ErrorCode::INVALID_PARAMS, '未选择登录企业，不可操作');
        }
        $params = [
            'name' => $this->request->input('name', null),
            'parentName' => $this->request->input('parentName', null),
            'page' => $this->request->input('current', 1),
            'perPage' => $this->request->input('size', 10),
        ];

        return $this->pageIndexLogic->handle($corp_id, $params);
    }
}
